package com.wyw.function.learning.demo2;

import com.wyw.function.learning.common.*;

/**
 * @Title   行为参数化
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * Update History:
 * Author        Time            Content
 */
public class DemoClient2 {

    /**
     *  这样做任何需求的变更，只需要增加相应的实现类即可，但是这样会产生一个问题：类膨胀
     *          所以可以采用匿名内部类的形式
     */
//    public static void main(String[] args) {
//        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), new AppleHeavyRedPredicate()));
//        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), new AppleHeavyWeightPredicate()));
//    }

    /**
     * 匿名内部类的方式
     */
    /*public static void main(String[] args) {
        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), new ApplePredicate() {
            @Override
            public boolean test(Apple apple) {
                return apple.getWeight()>150;
            }
        }));
        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), new ApplePredicate() {
            @Override
            public boolean test(Apple apple) {
                return "red".equalsIgnoreCase(apple.getColor());
            }
        }));
    }*/

    // 将匿名内部类换乘lambda
    public static void main(String[] args) {
        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), apple -> apple.getWeight() > 150));
        System.out.println(AppleClient.fileterApples(AppleClient.getApples(), apple -> "red".equals(apple.getColor())));
    }

}
